//
//  HomeSegRequest.m
//  BaseProject
//
//  Created by 王洋 on 2021/3/9.
//  Copyright © 2021 王洋. All rights reserved.
//

#import "HomeSegRequest.h"

@implementation HomeSegRequest

+ (void)request_homeSegWithParentId:(NSString *)parentId scType:(NSString *)scType comption:(void (^)(BOOL success, NSMutableArray<HomeFlowSegmentModel *>*segDataArray))comption {
    
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:parentId forKey:@"parentId"];
    [dic setValue:scType forKey:@"scType"];
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_HomeCategory];

    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        if ([data isKindOfClass:[NSDictionary class]]) {
            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                NSMutableArray<HomeFlowSegmentModel *>*segDataArray = @[].mutableCopy;

                NSArray *oneList = [data valueForKey:@"data"];
                if ([oneList isKindOfClass:[NSArray class]]) {
                    for (int i = 0; i < oneList.count; i++) {
                        HomeFlowSegmentModel *oneModel = [HomeFlowSegmentModel modelWithDictionary:oneList[i]];
                        [segDataArray addObject:oneModel];
                    }
                }
                comption(YES,segDataArray);
            } else {
                comption(NO,@[].mutableCopy);
            }
        } else {
            comption(NO,@[].mutableCopy);
        }
    } FailedBlock:^(NSError * _Nonnull error) {
        comption(NO,@[].mutableCopy);
    }];

}

@end
